package com.earnings.okhttputils.utils.ui.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.earnings.R;


/*
消息对话框
 */
public class InfoDialog extends Dialog implements
		View.OnClickListener {
	private Activity act;
	private LinearLayout mView;
	private String sex;

	/**
	 * 初始化
	 *
	 * @param context
	 */
	public InfoDialog(Context context, String text) {
		super(context, R.style.dialog_msg);
		this.act = (Activity) context;

		mView = (LinearLayout) act.getLayoutInflater().inflate(R.layout.dialog_info,
				null);/*
		layout= (LinearLayout) mView.findViewById(R.id.cont);
		layout.getLayoutParams().width = act.getWindowManager()
				.getDefaultDisplay().getWidth();
*/
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		((TextView)mView.findViewById(R.id.text)).setText(text);

		mView.findViewById(R.id.sumbit).setOnClickListener(this);
		// setCanceledOnTouchOutside(false);
		// setCancelable(false);
		// init();
	}

	public void setSure(String text, View.OnClickListener listener){
		((TextView)mView.findViewById(R.id.sumbit)).setText(text);
		mView.findViewById(R.id.sumbit).setOnClickListener(listener);
	}


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// setContentView(layout);
		this.setCancelable(true);// 可以用“返回键”取消
		Window window = this.getWindow();
		window.setContentView(mView);
		window.setGravity(Gravity.CENTER); // 此处可以设置dialog显示的位置
	}

	@Override
	public void dismiss() {
		// TODO 自动生成的方法存根
		super.dismiss();
		// TextView tv=(TextView) act.findViewById(R.id.province);
		// tv.setText(province);
	}

	public void setTitle(String title){
		TextView tvTitle= (TextView) mView.findViewById(R.id.title);
		tvTitle.setText(title);tvTitle.setVisibility(View.VISIBLE);
	}
	@Override
	public void onClick(View v) {
		dismiss();
	}

}
